package com.vaadin.tutorial.crm.backend.repository;

import com.vaadin.tutorial.crm.backend.entity.Student;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface StudentRepository extends JpaRepository<Student, Long> {

    @Query("select stu from Student stu " +
            "where lower(stu.stuName) like lower(concat('%', :searchTerm, '%')) " +
            "or lower(stu.stuNum) like lower(concat('%', :searchTerm, '%'))")
    List<Student> search(@Param("searchTerm") String searchTerm);

    @Query("select stu from Student stu where stu.stuId = ?1")
    Student getStuByStuId(Integer stuId);
}
